package com.soluzionasf.zeus;

import org.eclipse.ui.IMemento;
import org.eclipse.ui.application.IWorkbenchConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

import com.soluzionasf.zeus.uitoolkit.UIToolkitPlugin;

public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {

	/**
	 * {@inheritDoc}
	 */
	@Override
	public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
			IWorkbenchWindowConfigurer configurer) {
		return new ApplicationWorkbenchWindowAdvisor(configurer);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void initialize(IWorkbenchConfigurer configurer) {
		super.initialize(configurer);
		configurer.setSaveAndRestore(true);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String getInitialWindowPerspectiveId() {
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void postShutdown() {
		UIToolkitPlugin.getDefault().saveWorkbenchState();
		UIToolkitPlugin.getDefault().saveKeybindingState();
		super.postShutdown();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void preStartup() {
		IMemento memento = UIToolkitPlugin.getDefault().loadWorkbenchState();
		String keybindingStore = UIToolkitPlugin.getDefault().loadKeybindingState();
		UIToolkitPlugin.getDefault().saveKeybindingToFile(keybindingStore);
		UIToolkitPlugin.getDefault().saveWorkbenchStateToFile(memento);
		super.preStartup();
	}
}
